from django.db import models
from django.contrib.auth.models import AbstractUser

from utils.models import TimeStampedModel


class UserProfile(AbstractUser):
    GENDER_CHOICES = (
        ('male', '男'),
        ('female', '女')
    )
    nickname = models.CharField(max_length=25, verbose_name='昵称', default='')
    birthday = models.DateField(verbose_name='生日', blank=True, null=True)
    gender = models.CharField(choices=GENDER_CHOICES, verbose_name='性别', max_length=10, default='female')
    address = models.CharField(max_length=100, verbose_name='地址')
    telephone = models.CharField(max_length=11, blank=True, null=True, verbose_name='手机')
    image = models.ImageField(upload_to='avatar/%Y/%m', default='image/default.png', max_length=100, verbose_name='头像')

    class Meta:
        verbose_name = '用户账号'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class EmailVerifyRecord(models.Model):
    VERIFY_TYPE_CHOICES = (
        ('register', '注册'),
        ('forget', '忘记密码找回')
    )
    code = models.CharField(max_length=20, verbose_name='验证码')
    email = models.EmailField(max_length=50, verbose_name='邮箱')
    verify_type = models.CharField(choices=VERIFY_TYPE_CHOICES, max_length=10, verbose_name='验证类型')
    send_time = models.DateTimeField(auto_now_add=True, verbose_name='发送时间')

    class Meta:
        verbose_name = '邮箱验证码'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '{} to {}'.format(self.code, self.email)


class Banner(TimeStampedModel):
    title = models.CharField(max_length=100, verbose_name='标题')
    image = models.ImageField(upload_to='banner/%Y/%m', verbose_name='轮播图', max_length=100)
    url = models.URLField(max_length=200, verbose_name='访问地址')
    index = models.IntegerField(default=100, verbose_name='顺序')

    class Meta:
        verbose_name = '轮播图'
        verbose_name_plural = verbose_name




